"""
@name : 面向对象
@author : shiyaling
@projectname : xsfh
"""
import subprocess
import os
class shell():
    def __init__(self,user1):
        self.user1 = user1

    def useradd(self):
        re1 = subprocess.call('useradd %s'%self.user1,shell=True)
        if re1 == 0:
            print("新建用户{self.user1}成功")

class A(shell):
    def __init__(self,user2):
        self.user2 = user2

    def __checkuid__(self):
        print("用户的uid是")
        subprocess.Popen('id -u %s'%self.user2,shell=True)
    def __checkgid__(self):
        print("用户的gid是")
        subprocess.Popen('id -g %s'%self.user2,shell=True)
    def __changeuid__(self,uid):
        re2 = subprocess.call('usermod -u %s %s'%(uid,self.user2),shell=True)
        if re2 == 0:
            print("uid修改成功")
    def __changegid__(self,gid):
        re3=subprocess.call('usermod -g %s %s'%(gid,self.user2),shell=True)
        if re3 == 0:
            print("gid修改成功")
    def __changesh__(self,sh):
        re4 = subprocess.call('usermod -s %s %s'%(sh,self.user2),shell=True)
        if re4 == 0:
            print("用户登入的shell修改成功")

class B(shell):
    def __deleteuser__(self,user3):
        re1 = subprocess.call('userdel %s'%user3,shell=True)
        if re1 == 0:
            print(f"用户{user3}删除成功")
    def __deletegroup__(self,group1):
        re2 = subprocess.call('groupdel %s'%group1,shell=True)
        if re2 == 0:
            print(f"{group1}删除成功")


class C(A,B):
    def __init__(self,group2):
        self.group2 = group2

    def __usergroup__(self):
        re1 = subprocess.call('groupadd %s'%self.group2,shell=True)
        if re1 == 0:
            print(f"新建组{self.group2}创建成功")
    def __changeggid__(self,user):
        try:
            gid = os.popen("awk -F ':' 'END {print$3}' /etc/group").readlines()
            re2 = subprocess.call(f'sudo usermod -g {gid} {user}', shell=True)
            if re2 == 0:
                print(f"{user}的gid修改成功")
        except Exception as e:
            print(f"error:{e}")
